package com.ictology.mei;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Button;

public class ContactActivity_fragment extends Fragment {

    public static ContactActivity_fragment newInstance() {
        ContactActivity_fragment fragment = new ContactActivity_fragment();
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }



    EditText yourName, yourEmail, content;
    Button submit_btn;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_contact_fragment, container, false);
        yourName =(EditText) view.findViewById(R.id.yourName_editText);
        yourEmail =(EditText) view.findViewById(R.id.yourName_editText);
        content =(EditText) view.findViewById(R.id.content);
        submit_btn = (Button) view.findViewById(R.id.submit_btn);
        submit_btn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){
                String to = "emma@happymacao.com";
                String subject = "Ma\"s 創業廚房—疑問/建議/查詢";
                String name = yourName.getText().toString();
                String email = yourEmail.getText().toString();
                String message = content.getText().toString();
                Intent intent = new Intent(Intent.ACTION_SENDTO);
                intent.putExtra(Intent.EXTRA_EMAIL, to);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
                    intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(new StringBuilder()
                            .append("<div>名字："+name+"</div>")
                            .append("<div>電郵："+email+"</div>")
                            .append("<div>內容："+message+"</div>")
                            .toString(),Html.FROM_HTML_MODE_LEGACY));
                } else {
                    intent.putExtra(Intent.EXTRA_TEXT,  Html.fromHtml(new StringBuilder()
                            .append("<div>名字："+name+"</div>")
                            .append("<div>電郵："+email+"</div>")
                            .append("<div>內容："+message+"</div>")
                            .toString()));
                }
                intent.setType("message/rfc822");
                startActivity(Intent.createChooser(intent, "Select a Email app"));
            }
        });
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        TextView title=(TextView)getActivity().findViewById(getResources().getIdentifier("action_bar_title", "id", getActivity().getPackageName()));
        title.setText("關於我們");
    }
}
